#!/bin/bash

set -ex
set -o pipefail

if [ -z "$1" ]
then
        BRANCH='master'
else
        BRANCH=$1
fi

WORK_DIR=$(cd "$(dirname $0)";pwd)
PACKAGES=${WORK_DIR}/${BRANCH}/packages
SDK_DIR=${WORK_DIR}/${BRANCH}/sdk
commit_id=`docker exec -it  llvm-build /bin/bash -c "cd /srv/workspace/llvm-release/${BRANCH}/toolchain/llvm-project && git rev-parse --short HEAD"`
commit_id=$(echo $commit_id | sed 's/\r//g')
commit_id=$(echo ${commit_id:0:6})
SDK_HOME=/srv/wrokspace/sdk/${BRANCH}
OUT_HOME=/srv/wrokspace/ohos/openharmoney/out/sdk/sdk-native/os-specific
date="20250320" 

#docker exec -it  ohos-build /bin/bash -c "mkdir -p ${SDK_HOME}"
rm -rf ${SDK_DIR}
mkdir ${SDK_DIR}
cd ${PACKAGES}/target_location

# docker cp clang_linux-x86_64-${commit_id}-${date}.tar.gz ohos-build:${SDK_HOME}
# docker cp clang_windows-x86_64-${commit_id}-${date}.tar.gz ohos-build:${SDK_HOME}
# docker cp clang_ohos-arm64-${commit_id}-${date}.tar.gz ohos-build:${SDK_HOME}

# cd -

#docker exec -it  ohos-build /bin/bash -c "cd ${SDK_HOME}/../../ohos && rm -rf out && rm -rf prebuilts"
#docker exec -it  ohos-build /bin/bash -c "cd ${SDK_HOME}/../../ohos && repo sync -c && repo forall -c 'git lfs pull'"


docker exec -it  ohos-build /bin/bash -c "cd ${OUT_HOME}/linux && tar -zvcf llvm_linux.tar.gz ./llvm"
docker exec -it  ohos-build /bin/bash -c "cd ${OUT_HOME}/ohos && tar -zvcf llvm_ohos.tar.gz ./llvm"
docker exec -it  ohos-build /bin/bash -c "cd ${OUT_HOME}/windows && tar -zvcf llvm_windows.tar.gz ./llvm"
docker cp ohos-build:${OUT_HOME}/linux/llvm_linux.tar.gz ${SDK_DIR}
docker cp ohos-build:${OUT_HOME}/ohos/llvm_ohos.tar.gz ${SDK_DIR}
docker cp ohos-build:${OUT_HOME}/windows/llvm_windows.tar.gz ${SDK_DIR}